<template>
  <div class="login">
    <el-form :model="form" class="demo-ruleForm">
      <el-form-item label="账号" prop="pass">
        <el-input type="text" v-model="form.username" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="checkPass">
        <el-input type="password" v-model="form.password" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item style="text-align: center">
        <el-button type="primary" @click="submitForm('ruleForm')">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  data() {
    return {
      form: {}
    };
  },
  methods: {
    async submitForm() {
        const admin = await this.$http.post('/Login',this.form);
        sessionStorage.setItem('token',admin.data.token);
        sessionStorage.setItem('userInfo',JSON.stringify({name:admin.data.name,img:admin.data.img}))
        // this.$store.commit('setToken',admin.data.token)
        // this.$store.commit('setUser',{name:admin.data.name,img:admin.data.img})
        this.$router.push('/')
        if (admin){
                this.$message({
                type:"success",
                message: "登陆成功"
            })
        }        
    }
  }
};
</script>
<style>
.login {
  margin: 0 auto;
  margin-top: 200px;
  width: 300px;
  padding: 20px 30px;
  border-radius: 2px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.04);
}
</style>